<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript">
	var flagCode=false;
	function loginFun() {
		if(!flagCode){
			$('#code').focus();
			return;
		}
		$('#login_Form').form('submit', {
			url : '${pageContext.request.contextPath}/userAction!login.action',
			success : function(data) {
				var obj = $.parseJSON(data);
				if (obj.success) {
					$('#login_dialog').dialog('close');
				}
				$.messager.show({
					title : '提示',
					msg : obj.msg,
					showType : 'slide'
				});
			}
		});
	}
	$(function() {
		$('#code').blur(function() {
			$.post("${pageContext.request.contextPath}/verifyCodeAction.action", {
				"code" : $(this).val()
			}, function(date) {
				if (date) {
					flagCode=true;
					$('#codefalid').hide();
					$('#codesuccess').show();
				}
				else {
					flagCode=false;
					$('#codesuccess').hide();
					$('#codefalid').show();
				}
			});
		});

		$('#image1').click(function() {
			$(this).attr("src", "imageAction.action?i=" + Math.random());
			return false;
		});

		$('#login_Form input').on('keyup', function(event) {
			if (event.keyCode == '13') {
				loginFun();
			}
		});
		$('#login_Form input[name=name]').focus();
	});
</script>
<div id="login_dialog" class="easyui-dialog" data-options="title:'登陆',modal:true,closable:false,
			buttons:[{
				text:'注册',
				handler:function(){
					$('#regForm input').val('');
					$('#regdialog').dialog('open');
				}
			},{
				text:'登陆',
				handler:function(){
					loginFun();
				}
			}]">
	<form id="login_Form" method="post">
		<table>
			<tr>
				<th>用户名:</th>
				<td>
					<input name="name" type="text" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入用户名'" />
				</td>
			</tr>
			<tr>
				<th>密码:</th>
				<td>
					<input name="pwd" type="password" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入密码'" />
				</td>
			</tr>
			<tr>
				<td>
					<a href="javascrip:;">
						<img src="${pageContext.request.contextPath}/imageAction.action" alt="验证码" title="点击更换" width="75" height="30" id="image1" />
					</a>
				</td>
				<td>
					<input name="code" id="code" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入验证码'" type="text" style="width:100px;"/>
					<a id="codesuccess" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" style="display:none"></a>
					<a id="codefalid" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true" style="display:none"></a>
				</td>
			</tr>
		</table>
	</form>
</div>